#pragma once 
#include "Header.h"
#include "Triangle.h"

namespace WINDX 
{
	class _declspec(dllexport) WinEX
	{
	private:
		static LRESULT CALLBACK WndHandle(HWND hwnd, UINT uint, WPARAM wparam, LPARAM lparam);
		HWND hwnd;
		MSG msg;
		HINSTANCE hInstance;
		WNDCLASSEX wndclass;
		BOOL isrunning;
		char mp_Class[20];
		IDirect3D9* g_d3d;
		IDirect3DDevice9* g_d3dDevice;
		Geometry::Triangle* m_tria;
	public:
		WinEX(std::string Title, SIZE sZ, POINT PT);
		WinEX(std::string Title, SIZE sZ);
		WinEX(std::string Title);
		~WinEX(){ };


		void InitWin(std::string Windowname, SIZE sz, POINT pnt);
		void InitDX();

		BOOL RunWin();

		void Show(){ ShowWindow(hwnd, SW_SHOW); }
		void Hide(){ ShowWindow(hwnd, SW_HIDE); }

		HWND GetHWND(){ return hwnd; }

		SIZE GetWindowSize()
		{
			RECT rct;
			GetClientRect(hwnd, &rct);
			SIZE sZ = { rct.right - rct.left, rct.bottom - rct.top };
			return sZ;
		}

		BOOL IsDepthFormatOk(D3DFORMAT DepthFormat, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat)
		{
			// Verify that the depth format exists
			HRESULT hr = g_d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT,
												  D3DDEVTYPE_HAL,
												  AdapterFormat,
												  D3DUSAGE_DEPTHSTENCIL,
												  D3DRTYPE_SURFACE,
												  DepthFormat);
			if(FAILED(hr)) return FALSE;
			// Verify that the depth format is compatible
			hr = g_d3d->CheckDepthStencilMatch(D3DADAPTER_DEFAULT,
											   D3DDEVTYPE_HAL,
											   AdapterFormat,
											   BackBufferFormat,
											   DepthFormat);
			return SUCCEEDED(hr);
		}

		void Render();
		IDirect3DDevice9* GetDevice(){ return g_d3dDevice; }
	};
}